<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty trimwhitespace outputfilter plugin
 *
 * File:     outputfilter.b2b.php<br>
 * Type:     outputfilter<br>
 * Name:     bar<br>
 * @param string
 * @param Smarty
 */
function smarty_outputfilter_pages($source, &$smarty)
{
    /*
    @header('Content-Type: text/html; charset=utf-8');
    $domain = addcslashes( HOST_WWW , '/');
    str_replace(HOST_WWW.'index.php', HOST_WWW.'index.html', $source);

    //detail.bookuu.com
    $source = preg_replace('/(href\=[\"|\'])('. addcslashes( HOST_DETAIL , '/') .'|' . $domain . ')\/detail\.php\?id=(\d+)([\"|\'])/', '$1'.HOST_DETAIL.'/$3.html$4', $source);
    //search.bookuu.com
    //$source = preg_replace('/(href\=[\"|\'])('. addcslashes( HOST_SEARCH , '/') .'|' . $domain . ')\/list\.php\?cd\[fl\]=(\d+)([\"|\'])/', '$1'.HOST_SEARCH.'/$3.html$4', $source);
    $source = preg_replace_callback('/(href|action)\=[\"|\'](.*?)list\.php(?:\?(.*?))?[\"|\']/', 'smarty_outputfilter_list', $source);
    //special.bookuu.com
    $source = preg_replace('/(href\=[\"|\'])('. addcslashes( HOST_SPECIAL , '/') .'|'. $domain .'\/special)\/special\.php\?id=(\d+)([\"|\'])/', '$1'.HOST_SPECIAL.'/$3.html$4', $source);
    $source = preg_replace('/(href\=[\"|\'])('. addcslashes( HOST_SPECIAL , '/') .'|'. $domain .'\/special)\/tequ\.php\?id=(\d+)([\"|\'])/', '$1'.HOST_SPECIAL.'/tequ/$3.html$4', $source);
    $source = preg_replace('/(href\=[\"|\'])('. addcslashes( HOST_SPECIAL , '/') .'|'. $domain .'\/special)\/special\.php\?tz=(\d+)([\"|\'])/', '$1'.HOST_SPECIAL.'/t_$3.html$4', $source);

    //$source = preg_replace('/\s(?=\s)/', '', $source);
    */
    return $source;
}

if (!function_exists('smarty_outputfilter_list')){
function smarty_outputfilter_list($matched){
    if ($matched[3]) {
        parse_str($matched[3], $url);
        $url['cd']['keywords'] && $url['cd']['keywords'] = urlencode($url['cd']['keywords']);
        $url = preg_replace('/%5B([a-z_0-9]+)%5D\=/', '%5B$1%5D_', http_build_query($url, '', '-'));
        $url = preg_replace('/(\w+)\=(\w+|\d+)/', '$1_$2', $url);
        return urldecode('href="'. HOST_SEARCH .'/'. $url. '.html"');
    }
    return 'href="' . HOST_SEARCH . '/search.php"';
}
}
?>
